package com.neu.wangweili.dao;

import com.neu.commons.Dao.BaseDao;

import java.util.List;
import java.util.Map;

public class StuInfoDao extends BaseDao {
    public  List<Map<String,Object>> StuLogin(Object...obj){
        List<Map<String,Object>> list=null;
        String sql="select * from t_stu_info "+
                " where stu_no=? and stu_pwd=?";
        list=BaseDaoQuery(sql,obj);
        return list;
    }
//    按学号或姓名或id查找
    public List<Map<String,Object>>findByNameOrNo(Object...obj){
        List<Map<String,Object>> list=null;
        String sql="select * from v_stuinfo"+
                " where stu_no=? or stu_name=? ";
        list=super.BaseDaoQuery(sql,obj);
        return list;
    }
//    按照id查找学生
public List<Map<String,Object>>findById(Object...obj){
    List<Map<String,Object>> list=null;
    String sql="select * from t_stu_info"+
            " where stu_id=?";
    list=super.BaseDaoQuery(sql,obj);
    return list;
}
//    删除学生
    public int delete(Object...params){
        int row=0;
        String sql="delete from t_stu_info"+
                " where stu_id=?";
        row=BaseDaoUpdate(sql,params);
        return row;
    }
//    修改学生
//    任命学生会
public int appointStu(Object...params){
    int row=0;
    String sql="update t_stu_info"+
            " set stu_statis=?"+
            " where stu_id=?";
    row=BaseDaoUpdate(sql,params);
    return row;
}
//获取总页数
    public List<Map<String,Object>>findPageNum(int pageCount){
        List<Map<String, Object>> list=null;
        String sql="select ceil(count(stu_id)/?) a from v_stuinfo";
        list=super.BaseDaoQuery(sql,pageCount);
        return list;
    }
//    获取每页记录
    public List<Map<String,Object>> findByPage(int pageIndex,int pageCount){
        List<Map<String,Object>>list=null;
        int end=pageIndex*pageCount;
        int begin=(pageIndex-1)*pageCount;
        String sql="select * " +
                " from" +
                " (select v.*,rownum r" +
                " from v_stuinfo v" +
                " where rownum<=?)a" +
                " where a.r>?";
        list=BaseDaoQuery(sql,end,begin);
        return list;
    }

}
